package com.herench.bs.handler;

import com.herench.bs.agent.IOutpatientClinicAgent;
import com.herench.bs.annotation.Handler;
import com.herench.bs.support.AbstractMessageHandler;
import com.herench.bs.support.RequestMessage;
import com.herench.bs.support.ResponseMessage;
import com.herench.bs.utils.DataFormatUtils;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * com.herench.bs.handler
 * Created by wenkai on 2017/09/05/13:37
 *
 * @Software: IntelliJ IDEA
 */
@Component
@Handler(code = "100703",name="当日科室排班查询")
public class RegistSchedulingHandler extends AbstractMessageHandler{


    @Override
    protected ResponseMessage innerHandler(RequestMessage requestMessage) throws Exception {
        ResponseMessage responseMessage = new ResponseMessage(requestMessage.getId());
        String channelCode = requestMessage.getArgsPropertyStringValue("sysCode");
        String deptCode = requestMessage.getArgsPropertyStringValue("deptId");
        IOutpatientClinicAgent outpatientClinicAgent = getCleverClinicContext().getApplicationContext().getBean(IOutpatientClinicAgent.class);
        String hospitalCode = getCleverClinicContext().getHospitalCodeByChannelCode(channelCode);
        Date dt = new Date();
        String text = DataFormatUtils.getWeekOfDate(dt);
        if (!(text.equals("星期六")||text.equals("星期日"))) {
            Map<String, Object> res = outpatientClinicAgent.loadCurrentDeptScheduling(channelCode, hospitalCode, deptCode);
            responseMessage.setData(res);
            getPropertiesFromInvokerResultMap(responseMessage, res);
        }else{
            Map<String, Object> res=new HashMap<>();
            res.put(ResponseMessage.RES_CODE, "-1");
            res.put(ResponseMessage.MESSAGE, "此功能六日不开放！");
            responseMessage.setData(res);
            getPropertiesFromInvokerResultMap(responseMessage, res);
        }
        return responseMessage;
    }

}
